<!doctype html>
<!--订阅规则-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>${title}</title>
<link rel="stylesheet" href="${base}/css/default.css" type="text/css">
<script type="text/javascript" src="${base}/js/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
$(function(){
	//区域选择-显示、隐藏层
	 $('#sa').click(function(){
		$('.mask').toggle();
		$('.sm-area-box').toggle();		
		$('html').toggleClass("ho"); 
	 });
	 $('.mask').click(function(){
		$(this).hide();
		$('.sm-area-box').hide();
	    $('html').toggleClass("ho");
	 });
	 $('.sa-r-box span').click(function(){ 
		$('.sm-area-box, .mask').hide();
	    $('html').toggleClass("ho");
	 });
	//区域选择-选择地区
	$(".sa-r-box").hide();
	$(".sa-l ul li:first").addClass("active").show();
	var pid = $(".sa-l ul li:first").find("span").attr("value")
	var name = $(".sa-l ul li:first").find("span").html();
	getCity(pid,name);
	$(".sa-r-box").show();
	$(".sa-l li").click(function() {
		$(".sa-l li").removeClass("active");
		$(this).addClass("active");
		$(".sa-r-box").hide(); 
		var provinceId = $(this).find("span").attr("value");
		var provincename = $(this).find("span").html();
		getCity(provinceId,provincename);
		$(".sa-r-box").fadeIn(0);
	});	
	
	function getCity(id,name){
		$.ajax({
			url:'${base}/selector/getCity',
			method:'get',
			dataType:'json',
			data:{provinceId:id},
			async:false,
			success:function(data){
				$('#tab1 ul').empty();
				name = name+"全省";
				$('#tab1 ul').append('<li><span onclick="javascript:getIt(this);" value="'+id+'" type="1">'+name+'</span></li>');
				for(var i=0;i<data.length;i++){
					$('#tab1 ul').append('<li><span onclick="javascript:getIt(this);" value="'+data[i].id+'"  type="2">'+data[i].name+'</span></li>');
				}
			}
		})
	}
	
	//搜索条件收起	
	 $('.row-head').click(function(){	
		$(this).parent().toggleClass("hrb"); 
	 });
	 
	//规则管理
	 $('.dl-mg-box').hide();
	 $('.dl-mg').click(function(){
		$(this).next().toggle(); 
		$('html').toggleClass("ho8"); 
	 });
	 $('.mask8').click(function(){
		$('.dl-mg-box').hide();
	    $('html').toggleClass("ho8");
	 });
	 
	 	var categorys = '${subscribeEntity.category}'.split(','); // 存放类别数组
	 	var categorysStr = '${categoryStr}'.split(',');
	 	$('#category-label').html(categorysStr.join(','));
	 	$('#category li').each(function(index,element){
	 		var value = $(this).find('span').attr('value');
	 		if(categorys.indexOf(value)>-1){
		 		$(this).addClass("sc");
	 		}
	 	})
	  $('#category li').click(function(){
	 		$(this).toggleClass("sc");
	 		//$(this).addClass("sc");
	 		var catgoryHTML = $(this).find('span').html();
	 		//console.log(catgoryHTML)
	 		var value = $(this).find('span').attr('value');
	 		
	 		if(categorys.indexOf(value)==-1){
		 		categorysStr.push(catgoryHTML);
		 		categorys.push(value);
		 		
	 		}else{
	 			categorysStr.splice(categorys.indexOf(value),1);
	 			categorys.splice(categorys.indexOf(value),1);
	 		}
	 		//console.log(categorysStr)
	 		$('#category-label').html(categorysStr.join(','));
	 		$('input[name="category"]').val(categorys.join(','));
	 });
	 
	 	var columns = '${subscribeEntity.column}'.split(','); // 存放类别数组
	 	var columnsStr = '${columnStr}'.split(',');
	 	$('#column li').each(function(index,element){
	 		var value = $(this).find('span').attr('value');
	 		if(columns.indexOf(value)>-1){
		 		$(this).addClass("sc");
	 		}
	 	})
	 	$('#column-label').html(columnsStr.join(','));
	  $('#column li').click(function(){
	 		$(this).toggleClass("sc");
	 		//$(this).addClass("sc");
	 		var columnHTML = $(this).find('span').html();
	 		var value = $(this).find('span').attr('value');
	 			if(columns.indexOf(value)==-1){
		 		columnsStr.push(columnHTML);
		 		columns.push(value);
		 		
	 		}else{
	 			columnsStr.splice(columns.indexOf(value),1);
	 			columns.splice(columns.indexOf(value),1);
	 		}
	 		//console.log(categorysStr)
	 		$('#column-label').html(columnsStr.join(','));
	 		$('input[name="column"]').val(columns.join(','));
	 });
	 
	  $('#sub-btn').on('click',function(){
	 
	 	$('input[name="keywords"]').val('');
	 	$('input[name="scope"]').val('');
	 	
	 	$('input[name="keywords"]').val($('#keywords').val());
	 	$('input[name="scope"]').val($('#scope').val());
	 	
	 	var keywords = $('input[name="keywords"]').val();
	 	var scope = $('input[name="scope"]').val();
	 	var areaType = $('input[name="areaType"]').val();
	 	var area = $('input[name="area"]').val();
	 	var category = $('input[name="category"]').val();
	 	var column = $('input[name="column"]').val();
	 	$.ajax({
	 		'url':'${base}/subscribe/save',
	 		'type':'post',
	 		'data':{id:'${subscribeEntity.id}',keywords:keywords,scope:scope,areaType:areaType,area:area,category:category,column:column},
	 		success:function(data){
	 			var obj = JSON.parse(data);
	 			alert(obj.msg);
	 			window.location.href="${base}/subscribe/rule";
	 		}
	 	})
	 });
	 
	 //全文 标题选项卡初始化
	 $('#scope').val('${subscribeEntity.scope}');
});
</script>
</head>
<body>
<div class="mask"></div>
<div class="mask8"></div>
<header><a href="${base}/subscribe/rule" class="back"><span>返回</span></a><h2>修改订阅规则</h2></header>
<nav>
  <ul>
    <li class="n1"><a href="${base}/index/index"><cite></cite><span>首页</span></a></li>
    <li class="n2"><a href="${base}/search/index"><cite></cite><span>搜索</span></a></li>
    <li class="n3"><a href="${base}/subscribe/index" class="on"><cite></cite><span>订阅</span></a></li>
    <li class="n4"><a href="${base}/center/index"><cite></cite><span>我的</span></a></li>
  </ul>
</nav>
<div class="main rss-rule">
	<div class="sm-box">
    	<div class="sm-row sm-kw2">
            <div class="row-head"><label>关键字：</label></div>
            <div class="sm-kw2-sc">
                <div class="ft"><input id="keywords" type="text" placeholder="请输入关键字" value="${subscribeEntity.keywords}"/></div>
                <div class="fs">
                    <select id="scope">
                        <option value="all">全文</option>
                        <option value="title">标题</option>
                    </select>
                    <em></em>
                </div>
            </div>
        </div>
    	<div class="sm-row sm-area">
        	<div class="row-head"><label>地区：</label><input type="text" id="sa" placeholder="请选择地区" value="${area.name}" readonly /><em></em></div>
			<div class="sm-area-box">
            	<div class="sa-l">
                	<ul>
                    	<#list provinceList as province>
			                <li><span value="${province.id}">${province.name}</span></li>
			             </#list>
                    </ul>
                </div>
                <div class="sa-r">
                    <div id="tab1" class="sa-r-box">
                    	<ul>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    	<div class="sm-row">
        	<div class="row-head"><label>信息分类：</label><span id="category-label"></span><em></em></div>
            <div class="row-body clearfix" id="category">
                <ul>
                   <#list categoryList as category>
                    	<li><span value="${category.id}">${category.name}</span></li>
                    </#list>
                </ul>
            </div>
        </div>
    	<div class="sm-row">
        	<div class="row-head"><label>项目分类：</label><span id="column-label"></span><em></em></div>
            <div class="row-body clearfix" id="column">
                <ul>
                  <#list columnList as column>
                    	<li><span value="${column.id}">${column.name}</li>
                    </#list>
                </ul>
            </div>
        </div>
    </div>
    <div class="btn"><input id="sub-btn" type="button" value="订阅"  class="btn-o" /></div>
    <div class="li-hd"><a href="#" title=""><h3>规则列表</h3><em></em></a></div>
    <div class="dli clearfix">
    	<ul>
        	
        		<#list sublist as subscribe>
        		<li>
            	<a href="" title="">
                	<div class="dli-box">
                        <strong>${subscribe.area}+${(subscribe.column)!''}+${(subscribe.keywords)!''}</strong>
                        <div><p>关键词订阅次数:${(subscribe.num)!''}次</p></div>
                    </div>
                </a>
                <div class="dl-mg"><span>管理</span></div>
                <div class="dl-mg-box" style="display:none">
                	<dl >
                    	<dd><a href="javascript:deleteById('${subscribe.id}')" title="">删除规则</a></dd>
                    	<dd><a href="javascript:updateById('${subscribe.id}')" title="">修改规则</a></dd>
                    </dl>
                </div>
                </li>
                </#list>
        </ul>
    </div>
</div>
	<input type="hidden" name="keywords" value="${subscribeEntity.keywords}"/>
	<input type="hidden" name="scope" value="${subscribeEntity.scope}"/>
	<input type="hidden" name="area" value="${subscribeEntity.area}"/>
	<input type="hidden" name="areaType" value="${subscribeEntity.areaType}"/>
	<input type="hidden" name="category" value="${subscribeEntity.category}"/>
	<input type="hidden" name="column" value="${subscribeEntity.column}"/>

<script  type="text/javascript">
	
	 function getIt(obj){
	 	//alert(obj.innerHTML)
	 	$("#sa").val(obj.innerHTML);
	 	var $v=$(obj);
	 	//console.log($v.attr('value'))
	 	$('input[name="area"]').val($v.attr('value'));
	 	$('input[name="areaType"]').val($v.attr('type'));
	 	$('.sm-area-box, .mask').hide();
	  	$('html').toggleClass("ho");
	 }
	 
	  function deleteById(id){
	 	if(confirm('确定删除吗？'))
		{
		
			$.ajax({
				'url':'${base}/subscribe/deleteById',
				'type':'post',
				'data':{id:id},
				'dataType':'json',
				success:function(data){
					if(data.type=='1'){
						alert(data.msg)
						window.location.href="${base}/subscribe/rule";
					}
				}
			});
		
		}
	 }
	 
	 function updateById(id){
	 	window.location.href="${base}/subscribe/updateById?id="+id;
	 }
</script>
</body>
</html>
